// ./utils/CustomError.js

/**
 * 自定义 HTTP 错误类
 * 用于抛出特定状态码的业务错误
 */
class CustomError extends Error {
    constructor(message, status = 500) {
        super(message);
        this.status = status;
        this.isCustom = true; // 标记为自定义错误
        Error.captureStackTrace(this, this.constructor);
    }
}

// 常用快捷类
class BadRequestError extends CustomError {
    constructor(message = '请求参数错误') {
        super(message, 400);
    }
}

class UnauthorizedError extends CustomError {
    constructor(message = '认证失败或权限不足') {
        super(message, 401);
    }
}

module.exports = { CustomError, BadRequestError, UnauthorizedError };
